package cn.stronglink.assetmanage.business.inventory.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Inventory;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;

/**
 * 盘点单列表
 * @author zww
 *         2018 2018/6/10 18:13
 */
public class InventoryListAdapter extends RecyclerView.Adapter<InventoryListAdapter.ViewHolder> {
    private Context mContext;
    private List<Inventory> datas;
    private onRecyclerListener listener;

    public InventoryListAdapter(Context context,List<Inventory> datas) {
        this.mContext = context;
        this.datas = datas;
    }

    @Override
    public InventoryListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =LayoutInflater.from(mContext).inflate(R.layout.item_check_list,parent,false);
        return new InventoryListAdapter.ViewHolder(view, listener);
    }

    @Override
    public void onBindViewHolder(InventoryListAdapter.ViewHolder holder, int position) {
        Inventory inventory = datas.get(position);
        holder.tv_order_name.setText(inventory.getId_());
    }

    @Override
    public int getItemCount() {
        return datas==null?0:datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<Inventory> data) {
        this.datas = data;
        this.notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView tv_order_name;
        private onRecyclerListener listener;

        public ViewHolder(View itemView, onRecyclerListener listener) {
            super(itemView);
            this.listener = listener;
            tv_order_name = itemView.findViewById(R.id.tv_check_order_name);
            itemView.setOnClickListener(this);
//            tv_order_name.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onItemClicked(v, getAdapterPosition());
            }
        }
    }

}
